package com.mmall.concurrency.immutable;

import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;

import java.util.Collections;
import java.util.Map;

/**  基本变量和引用变量编译报错
 *   引用变量不可以再指向， 但是可以修改里面的值
 */

/**
 * Exception in thread "main" java.lang.UnsupportedOperationException
 * 	at java.util.Collections$UnmodifiableMap.put(Collections.java:1457)
 * 	at com.mmall.concurrency.immutable.UnmodifyCLASS.main(UnmodifyCLASS.java:27)
 */
@Slf4j
public class UnmodifyCLASS {

    public static Map<Integer, Integer> map = Maps.newHashMap();

    static {
        map.put(1,2);
        map.put(2,5);
        map.put(3,6);
        // 去掉上面final修饰
        map = Collections.unmodifiableMap(map);
    }

    public static void main(String[] args) {

        map.put(1, 10100111);
        log.info("修改成功：{}", map.get(1));
    }

}
